use iced::{
    Center, Element,
    widget::{button, center, column, text},
};

pub fn main() -> iced::Result {
    iced::run(Counter::update, Counter::view)
}

/// Widget: Counter
#[derive(Default)]
struct Counter {
    value: i64,
}

// Messages
#[derive(Debug, Clone, Copy)]
enum Message {
    Inc,
    Dec,
}

impl Counter {
    // Updater
    fn update(&mut self, message: Message) {
        match message {
            Message::Inc => {
                self.value += 1;
            }
            Message::Dec => {
                self.value -= 1;
            }
        }
    }

    // View
    fn view(&self) -> Element<Message> {
        center(
            column![
                button("Increment").on_press(Message::Inc),
                text(self.value).size(50),
                button("Decrement").on_press(Message::Dec),
            ]
            .padding(20)
            .align_x(Center)
         )
        .into()
    }
}
